package com.xinghou.mq.consumer;

import com.xinghou.mq.UserInterface;
import com.xinghou.platform.entity.req.MsgInfoReq;
import com.xinghou.platform.entity.resp.MsgInfo;
import com.xinghou.platform.model.main.LoginHistory;
import com.xinghou.platform.model.main.User;
import com.xinghou.platform.server.api.bussiness.LoginHistoryService;
import com.xinghou.platform.server.api.bussiness.MsgInfoBusinessService;
import com.xinghou.platform.server.mq.MqMessage;
import com.xinghou.platform.util.JsonUtil;

import javax.annotation.Resource;

/**
 * 消费用户消息 user
 * 
 * @author zhangjinwen 2016年1月6日
 */
public class UserConsumer  extends AbstractConsumer {
	private UserInterface userMqInterface;
	private LoginHistoryService loginHistoryService;
	private MsgInfoBusinessService msgInfoBusinessService;

	public UserConsumer() {
		userMqInterface = this.getBean(UserInterface.class);
		loginHistoryService=this.getBean("loginHistoryService");
		msgInfoBusinessService=this.getBean(MsgInfoBusinessService.class);
	}

	protected void doWork(String task) {
		String[] datas = task.split(":");
		userMqInterface.update(Integer.parseInt(datas[0]), datas[1].equals("U"));
	}
	public void doHuanxinRegister(String task)
	{
		String []datas=task.split(":");
		userMqInterface.HuanXinRegister(Integer.parseInt(datas[0]),datas[1]);
	}

	public void addUserHistorey(String historey)
	{
		LoginHistory loginHistory= (LoginHistory) JsonUtil.fromJson(historey,LoginHistory.class);
		loginHistoryService.insertLoginHistory(loginHistory);
	}
	public void updateUserGPS(String message)
	{
		MsgInfoReq msgInfoReq= (MsgInfoReq) JsonUtil.fromJson(message,MsgInfoReq.class);
		msgInfoBusinessService.updateUserLocation(msgInfoReq);

	}



}
